package com.ybybh.gamecenter.controller;

import com.ybybh.gamecenter.entity.News;
import com.ybybh.gamecenter.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class NewsController {
    @Autowired
    private NewsService newsService;

    //方法:展现新闻列表的控制器方法
    @RequestMapping("/NewsList")
    public ModelAndView toNewsList(){
        //1.获取新闻列表
        //即调用NewsService中的findAll()方法
        List<News> newsList = newsService.findAll();
        //2.把新闻列表传递到新闻列表页面上去，并跳转到新闻列表页面
        ModelAndView ModelAndView = new ModelAndView();
        ModelAndView.addObject("newsList",newsList);
        ModelAndView.setViewName("news");
        return ModelAndView;
    }

}
